package com.itheima.dao;

import com.itheima.pojo.Item;
import com.itheima.pojo.Order;
import com.itheima.pojo.User;
import org.apache.ibatis.annotations.*;

public interface OrderMapper {
    @Select("SELECT\n" +
            "\to.id oid,\n" +
            "\to.order_number,\n" +
            "\tu.* \n" +
            "FROM\n" +
            "\ttb_order o,\n" +
            "\ttb_user u \n" +
            "WHERE\n" +
            "\to.user_id = u.id \n" +
            "\tAND o.order_number = #{s};")
    @Results({
            @Result(column ="oid" ,property = "id", id = true),
            @Result(column ="order_number" ,property = "orderNumber"),
            @Result(column ="id" ,property = "user",javaType = User.class, one =@One(
select ="com.itheima.dao.UserMapper.findUbyId"
            ))


    })
    Order find(@Param("s") String s);


    //根据用户id查询订单信息
    @Select("\tSELECT * FROM tb_order WHERE tb_order.id\n" +
            "\t=#{id};")
    @Results({
            @Result(column ="id" ,property = "id", id = true),
            @Result(column = "order_number",property = "orderNumber"),
            @Result(column ="id" ,property = "item",javaType = Item.class,one = @One(
                    select ="com.itheima.dao.ItemMapper.find02" //指向订单明细 根据订单 id 查询 对应 的 商品 明细 id
            ))
    })
    Order findOrderByUid(int id);


}
